import numpy as np

np.set_printoptions(precision=40)

a = np.array([-4.78704,7.29176,3.12263,-8.72102,6.54695,0.408178,-4.7643,8.49932,4.50451,4.82586,-1.61296,-6.11842,6.81645,-4.72776,9.40993,9.21799,6.30043,0.356149,9.26544,0.188188,6.08789,-2.20969,-3.79914,4.79643,6.3003,5.77904,8.94648,-5.96991,3.8167,-0.0843859,-4.35136,5.73947,-7.23059,-5.68433,-7.1156,6.5942,-5.82258,8.67612,2.28971,-5.46597,-6.2194,-2.35787,-4.4362,6.91762,3.8671,2.11413,-1.71618,-4.32053,-8.21891,9.02178,-4.26638,6.41182,8.89988,-9.22317,9.2729,-3.42687,-2.20216,8.36345,-3.33361,-0.582502])
b = np.array([-5.87369,6.04822,-3.36429,-5.21126,6.11504,6.70013,7.18409,9.47699,6.64836,-9.85381,7.89421,-4.50139])

a = a.reshape(1,3,4,5) # c d h w
b = b.reshape(1,2,3,2)


# outputDim = 1 + ( inputDim + 2*pad - (((filterDim-1)*dilation)+1) )/convolutionStride;
# h_length = 1 + (a.shape[0]  + 2 * 1 - ((b.shape[0] - 1) * 1 + 1))/1 
# w_length = 1 + (a.shape[1]  + 2 * 1 - ((b.shape[1] - 1) * 1 + 1))/1 
h_length = a.shape[1] + b.shape[1] - 1
w_length = a.shape[2] + b.shape[2] - 1
d_length = a.shape[3] + b.shape[3] - 1


res = np.array(np.zeros(5 * 12 * 6).reshape(5,12,6), dtype = complex)



for i in range(a.shape[0]):
    # padding 
    a_i = np.pad(a[i], ((0,(int)(h_length -a.shape[1])) ,(0,(int)(w_length-a.shape[2])),(0,(int)(d_length-a.shape[3]))),'constant')
    b_i = np.pad(b[i], ((0,(int)(h_length -b.shape[1])) ,(0,(int)(w_length-b.shape[2])),(0,(int)(d_length-b.shape[3]))),'constant')


    print('a_i before')
    print(a_i.ravel())
    print('b_i before')
    print(b_i)
    a_i = np.fft.fftn(a_i)
    b_i = np.fft.fftn(b_i)
    b_i.imag *= -1


    print('a_i after')
    print(a_i)
    print('b_i after')
    print(b_i)
    c_i = a_i * b_i

    print('np.fft.ifftn(c_i)')
    print(np.fft.ifftn(c_i))
    
    # print(np.array(np.fft.ifftn(c_i)))

print('res')
# print(res)

# print(np.fft.fft2(a))


